﻿using System;
using System.Runtime.InteropServices;
using OdsServer.Common.Packet;

namespace OdsServer.Common.DataTransfer
{
    public interface IMarshalDataChunk
    {
        int GetDataChunkLength();
        int GetDataChunkBytes();
        Type GetDataChunkType();
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
    public struct MarshalMessageDataChunk: IMarshalDataChunk
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst=MessagePacket.MESSAGE_LENGTH)]
        internal char[] chunk;

        public MarshalMessageDataChunk(char[] chunk)
        {
            this.chunk = chunk;
        }

        public char[] GetDataChunk()
        {
            return this.chunk;
        }

        public int GetDataChunkLength()
        {
            return chunk.Length;
        }

        public int GetDataChunkBytes()
        {
            return Buffer.ByteLength(this.chunk);
        }

        public Type GetDataChunkType()
        {
            return typeof(char);
        }

        #region IMarshalDataChunk Members


        #endregion

        #region IMarshalDataChunk Members


        #endregion
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
    public struct MarshalChannelDataChunk : IMarshalDataChunk
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = MultiChannel8DataPacket.CHANNEL_COUNT)]
        internal ushort[] chunk;

        public MarshalChannelDataChunk(ushort[] chunk)
        {
            this.chunk = chunk;
        }

        public ushort[] GetDataChunk()
        {
            return this.chunk;
        }

        public int GetDataChunkLength()
        {
            return chunk.Length;
        }

        public int GetDataChunkBytes()
        {
            return Buffer.ByteLength(this.chunk);
        }

        public Type GetDataChunkType()
        {
            return typeof(ushort);
        }
    }
}